home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DATATYPE.SWG / 0006_MULTITYP.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  65 lines

  1. {
  2. >Is is Possible to have a File of Two different Record Types?
  3. >How would one do this? I have seen it done..
  4.  
  5. First, don't Declare the Type of the File, just use a Type or File.
  6.  
  7. Declare Pointer Variables For each Type that the Record can be.   if you want
  8. the Record to hold a Value that says what the Record Type is, then device an
  9. ID scheme, and make sure the ID Variables are physically located at the same
  10. Position in both Records.
  11.  
  12.  
  13. Read that data into a buffer Record With BlockRead.  Assign the Typed
  14. Pointers to that buffer, and process away....
  15. }
  16.  
  17. Type
  18.   onerec = Record  { Record size is 98 Bytes }
  19.     id : Byte;   { We will set ID = 1 For onerec }
  20.     Username : String[80];
  21.     Phone : String[15];
  22.   end;
  23.   anotherrec = Record  { Length is 163 Bytes }
  24.     id : Byte; {We will set ID = 2 For anotherrec }
  25.     ADDRESS1 : String[80];
  26.     ADDRESS2 : String[80];
  27.   end;
  28.  
  29. Var
  30.   ONE : ^ONEREC;
  31.   AnotHER : ^AnotHERREC;
  32.   Buffer : Array[1..163] of Char;   { The size of the largest Record }
  33.   F : File;
  34.   NumRead : Word;
  35.   ID : Byte Absolute Buffer;   { ID points to the first Char begin}
  36. begin
  37.   Assign(F,'FileNAME');
  38.   Reset(F,SizeOf(Buffer));
  39.   One := @BUFFER;
  40.   AnotHER := @BUFFER;
  41.   BlockRead(F,BUFFER,SIZEof(BUFFER),NUMRead);
  42.   While NumRead > 0 Do
  43.   begin
  44.     Case ID of
  45.       1 :
  46.         begin
  47.           WriteLn('Record is of Type ONE');
  48.           WriteLn('USERNAME: ',ONE^.USERNAME);
  49.           WriteLn('Phone: ',ONE^.Phone);
  50.         end;
  51.       2 :
  52.         begin
  53.           WriteLn('Record is of Type AnotHER');
  54.           WriteLn('Address Line 1 = ',AnotHER^.ADDRESS1);
  55.           WriteLn('Address Line 2 = ',AnotHER^.ADDRESS2);
  56.         end;
  57.       else
  58.         WriteLn('Unidentified Record Type');
  59.     end; { of Case }
  60.     BlockRead(F,BUFFER,SIZEof(BUFFER),NUMRead);
  61.   end;
  62.   Close(F);
  63. end.
  64.  
  65.